package com.hongyuan.venue.ui.home.activity;

import android.os.Bundle;

import androidx.lifecycle.ViewModelProviders;

import com.hongyuan.venue.R;
import com.hongyuan.venue.base.AppViewModelFactory;
import com.hongyuan.venue.base.CustomActivity;
import com.hongyuan.venue.data.Constants;
import com.hongyuan.venue.databinding.ActivityTrainListBinding;
import com.hongyuan.venue.ui.home.view_mode.TrainListViewModel;

import me.tatarka.bindingcollectionadapter2.BR;

public class TrainListActivity extends CustomActivity<ActivityTrainListBinding, TrainListViewModel> {

    @Override
    public int initContentView(Bundle savedInstanceState) {
        return R.layout.activity_train_list;
    }

    @Override
    public int initVariableId() {
        //注意了：这里是小写的viewModel
        return BR.viewModel;
    }

    @Override
    public TrainListViewModel initViewModel() {
        //使用自定义的ViewModelFactory来创建ViewModel，如果不重写该方法，则默认会调用NetWorkViewModel(@NonNull Application application)构造方法
        AppViewModelFactory factory = AppViewModelFactory.getInstance(getApplication());
        return ViewModelProviders.of(this, factory).get(TrainListViewModel.class);
    }

    @Override
    public void initView() {
        super.initView();

        setOnRefresh(binding.refresh,REFRESH_0X3);
        setEnableLoadMore(Constants.COURSE_TRAIN_LIST);
        setEnableRefresh(Constants.COURSE_TRAIN_LIST);

        binding.comBack.setOnClickListener(view -> finish());
    }

    @Override
    public void initData() {
        super.initData();

        viewModel.clearParams().setParams("os_id",viewModel.userToken.getOs_id());
        viewModel.requestData(Constants.COURSE_TRAIN_LIST);
    }
}
